package com.crm.dao.repositoryDAO;

import com.crm.pojo.Inandoutlog;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface InAndOutlogDAO extends CrudRepository<Inandoutlog,Long>, JpaSpecificationExecutor<Inandoutlog> {
    //分页查询所有的出入库流水根据时间排序
    @Query("from Inandoutlog log where log.inandoutlogIsDel='否' order by log.ioDate desc")
    public List<Inandoutlog> findAllByPaged(Pageable pageable);
    //查询所有内容 根据标题以及仓库名称模糊
    @Query(nativeQuery = true,value = "select log.* from INANDOUTLOG log join REPOSITORY r on log.IORID=r.RID where log.INANDOUTLOG_IS_DEL='否'and(r.RNAME like ?1 or log.IOTITLE like ?1) order by log.IO_DATE desc")
    public List<Inandoutlog> findAllIOByrnameOrtitle(String q);
    //查询所有出库 根据标题以及仓库名称模糊
    @Query(nativeQuery = true,value = "select log.* from INANDOUTLOG log join REPOSITORY r on log.IORID=r.RID where log.INANDOUTLOG_IS_DEL='否' and log.IOTYPE=1 and(r.RNAME like ?1 or log.IOTITLE like ?1) order by log.IO_DATE desc")
    public List<Inandoutlog> findAllIOByrnameOrtitle2(String q);
    //查询所有入库 根据标题以及仓库名称模糊
    @Query(nativeQuery = true,value = "select log.* from INANDOUTLOG log join REPOSITORY r on log.IORID=r.RID where log.INANDOUTLOG_IS_DEL='否' and log.IOTYPE=2 and(r.RNAME like ?1 or log.IOTITLE like ?1) order by log.IO_DATE desc")
    public List<Inandoutlog> findAllIOByrnameOrtitle3(String q);
    //查询对应rid下的log总数
    @Query(nativeQuery = true,value = "select count(*) from INANDOUTLOG io where io.IORID=?1 and io.INANDOUTLOG_IS_DEL='否'")
    public Long findCount(Long rid);

}
